//
//  HMCollectionViewCell.m
//  黑马彩票
//
//  Created by teacher on 15/3/3.
//  Copyright (c) 2015年 itheima. All rights reserved.
//

#import "HMCollectionViewCell.h"
#import "UIWindow+Extension.h"

@interface HMCollectionViewCell ()
@property (nonatomic, weak)IBOutlet UIImageView *bg;

@property (nonatomic, weak)IBOutlet UIButton *startBtn;
@property (weak, nonatomic) IBOutlet UIPageControl *PageControl;

- (IBAction)startBtnOnClick:(id)sender;
@end

@implementation HMCollectionViewCell

- (void)setIndexPath:(NSIndexPath *)indexPath count:(NSInteger)count
{
    // 2.根据页码生成图片名称
    NSString *bgName = [NSString stringWithFormat:@"start%ld", indexPath.item + 1];
    // 3.替换图片
    self.bg.image = [UIImage imageNamed:bgName];
    self.PageControl.numberOfPages=count;
    self.PageControl.currentPage=indexPath.item;
    // 4.控制开始按钮的显示
    if (indexPath.item == count - 1) {
        self.startBtn.hidden = NO;
        self.PageControl.hidden=NO;
    }else
    {
        self.startBtn.hidden = YES;
        self.PageControl.hidden= NO;
    }
}

- (IBAction)startBtnOnClick:(id)sender {
    // 1.拿到window
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window chooseRootViewController];
}
@end
